<?php
/*
客户跟进
*/
define('Acache_no','1');
class Con_log extends Acan{
	public $defaultAct='my';
	public $Conread = '日志';
	public $Actread = array('list'=>'所有日志','my'=>'我的日志');
	function __construct($ainfo=null){
		parent::__construct($ainfo=null);
		if(empty($this->id) || $this->id == '*'){$this->id = '0';}
		$this->uid = Afun_uid();
		$this->muser = Afun_db()->model(Acan_table_user);
		$this->mlog = Afun_db()->model(Acan_table_crm_log);
		//print_r($this->model);
		$this->_S = Afun_session();
	}
	//--所有用户
	function Act_list(){
		$this->atitle = '所有日志';
		return $this->Act_my();
	}
	//--自己客户
	function Act_my(){
		$op = Afunc_option();
		if(empty($this->atitle)){$this->atitle = '我的日志';}
		$uid = $this->uid;
		if($this->id>1){
			$uid = $this->id;
		}
		$get = $_GET;
		if(empty($get['date'])){
			$get['date'] = Afun_time_date(strtotime(date("Y").'-'.(date("n"))),"Y-m");
		}else{
			$where = " and a.date LIKE '".$get['date']."%'";
		}
		$this->model->enum['type']=array_merge(array(''=>""),Afunc_enum()->data('crm_log_type'));//获取用户QQ枚举
		$obj = Afun_acan_new('list');
		$key_name = $this->mlog->key_name;
		$columnrr['username'] = '员工';
		$columnrr['realname'] = '客户名称';
		$columnrr = array_merge($columnrr,$this->mlog->comment);//初始栏目
		unset($columnrr['uid']);
		$column = $obj->column($this->mlog,$columnrr,$_POST['acolumn']);
		unset($column[$this->mlog->key_name],$column['cid']);
		$column_html = $obj->column_html($this->mlog,$column,'Aform');
		//分页函数
		if($this->Aact=='list' && $this->uid==$uid){
			$con->where = "1".$where;
			if($this->_S['group']>1 && $this->_S['admin']==1){
				$adminjoin = " JOIN `".Acan_table_user_group."` g ON a.uid=g.uid";
				$con->where = "g.`group`=".$this->_S['group']." and g.appid=".Acan_app_id.$where;
			}
		}else if($this->Aact=='list' && $this->uid!=$uid){
			$con->where = "a.uid=$uid".$where;
		}else{
			$con->where = "a.uid=$this->uid".$where;//只能查看自己的客户
		}
		$con->where .= " and a.cid>0";//只显示有cid的客户
		$con->select = "a.*,b.username,c.realname";
		$con->join = "JOIN `".Acan_table_user."` b ON a.uid=b.uid JOIN `".Acan_table_crm_customer."` c on a.cid=c.cid".$adminjoin;
		$page->theurl = $this->Aactr.'-'.$this->id;
		$page->by = $this->mlog->key_name;
		$page->order = "DESC";
		$page->page = '20';
		$page->counts = $this->mlog->count($con);	//统计总数目
		$pages = Afun_apage($page);
		$con->order = "a.$pages->orderby";
		$con->limit = $pages->limit;
		//分页结束
		$list = $this->mlog->ofindAll($con);
		include $this->Atpl($this->Amod.'/my');
	}

}

?>